import Cookies from 'js-cookie'

const UserKey = 'hnt_avatar'

export function getToken() {
  const user = getUser()
  if (!user) {
    return ''
  }
  return user.token
}

export function setUser(user) {
  return Cookies.set(UserKey, JSON.stringify(user))
}

export function getUser() {
  const user = Cookies.get(UserKey)
  if (!user || user === '') {
    return {}
  }

  return JSON.parse(user)
}

export function removeUser() {
  return Cookies.remove(UserKey)
}
